<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Utility
 *
 * @author sakorn.s
 */
class Utility {

    function base64url_encode($data) {
        return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
    }

    function base64url_decode($data) {
        return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
    }

    function generate_random_password($length = 15) {
        $alphabets = range('A', 'Z');
        $numbers = range('0', '9');
        $alphalower = range('a','z');
        $additional_characters = array();
        $final_array = array_merge($alphabets, $numbers,$alphalower, $additional_characters);

        $password = '';

        while ($length--) {
            $key = array_rand($final_array);
            $password .= $final_array[$key];
        }

        return $password;
    }

}

?>
